package main

import "fmt"

//单指针:20ms 46%,6.4MB 37%
func exchange(nums []int) []int {
	i := 0
	for j := 0; j < len(nums); j++ {
		if nums[j]%2 == 1 {
			nums[j], nums[i] = nums[i], nums[j]
			i++
		}
	}
	return nums
}

//双指针:28ms 7%,6.4MB 74%
func exchange1(nums []int) []int {
	i, j := 0, len(nums)-1
	for i < j {
		for nums[i]%2 == 1 && i < j {
			i++
		}
		for nums[j]%2 == 0 && i < j {
			j--
		}
		nums[j], nums[i] = nums[i], nums[j]
	}
	return nums
}

func main() {
	fmt.Println(exchange([]int{2, 3, 5}))
	fmt.Println(exchange1([]int{2, 3, 5}))
}
